<?php

/**
 * This is the model class for table "{{haul}}".
 *
 * The followings are the available columns in table '{{haul}}':
 * @property string $id
 * @property string $trip_id
 * @property string $latitude_start
 * @property string $longitude_start
 * @property string $latitude_end
 * @property string $longitude_end
 * @property double $depth
 * @property integer $duration
 * @property string $create_time
 * @property string $create_user_id
 * @property string $update_time
 * @property string $update_user_id
 *
 * The followings are the available model relations:
 * @property Trip $trip
 * @property Yield[] $yields
 */
class Haul extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Haul the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{haul}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('trip_id, latitude_start, longitude_start, latitude_end, longitude_end, depth, duration, create_time, create_user_id, update_time, update_user_id', 'required'),
			array('duration', 'numerical', 'integerOnly'=>true),
			array('depth', 'numerical'),
			array('trip_id, create_user_id, update_user_id', 'length', 'max'=>10),
			array('latitude_start, longitude_start, latitude_end, longitude_end', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, trip_id, latitude_start, longitude_start, latitude_end, longitude_end, depth, duration, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'trip' => array(self::BELONGS_TO, 'Trip', 'trip_id'),
			'yields' => array(self::HAS_MANY, 'Yield', 'haul_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'trip_id' => 'Trip',
			'latitude_start' => 'Latitude Start',
			'longitude_start' => 'Longitude Start',
			'latitude_end' => 'Latitude End',
			'longitude_end' => 'Longitude End',
			'depth' => 'Depth',
			'duration' => 'Duration',
			'create_time' => 'Create Time',
			'create_user_id' => 'Create User',
			'update_time' => 'Update Time',
			'update_user_id' => 'Update User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('trip_id',$this->trip_id,true);
		$criteria->compare('latitude_start',$this->latitude_start,true);
		$criteria->compare('longitude_start',$this->longitude_start,true);
		$criteria->compare('latitude_end',$this->latitude_end,true);
		$criteria->compare('longitude_end',$this->longitude_end,true);
		$criteria->compare('depth',$this->depth);
		$criteria->compare('duration',$this->duration);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user_id',$this->create_user_id,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user_id',$this->update_user_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}